/** Mode handler for the world map.
@param map The map to handle.
*/
function WorldMapMode(map)
{
	this._map = map;
	this.render();
}
WorldMapMode.prototype =
{
	/** Handle an input action.
	 *@param action The action string to handle.
	*/
	handleAction: function(action)
	{
		switch(action)
		{
			case "up": this._map.tryMovePlayer(0, -1); break;
			case "down": this._map.tryMovePlayer(0, 1); break;
			case "left": this._map.tryMovePlayer(-1, 0); break;
			case "right": this._map.tryMovePlayer(1, 0); break;
			case "help":
				modeStack.push(new TextReaderMode(host.screen, "This is some\ntext and other junk! Yay!\nGots to get a text resource compiler soon...\n\n\n\nStuff!"));
				return true;
				break;
			case "use":
				this._map.tryUse();
				return true;
				break;
			case "look":
				modeStack.push(
					new SelectPositionMode(
						this._map,
						this._map.player.x,
						this._map.player.y,
						0,
						this._lookCallback,
						this
					)
				);
				return true;
				break;
			case "menu":
				modeStack.push(
					new MenuListMode(
						host.screen,
						20,
						"Main Menu",
						["Return to Game", "Save and Quit", "Quit Game"],
						this._menuCallback,
						this
					)
				);
				return true;
				break;
			default: return false; break;
		}
		this._updateStatus();
		return true;
	},
	/** Menu callback.
	*/
	_menuCallback: function(option)
	{
		switch(option)
		{
			case "Save and Quit":
				if(saveGame())
				{
					leaveGameMode();
					enterTitleMode();
				}
				break;
			case "Quit Game":
				modeStack.push(
					new MenuListMode(
						host.screen,
						30,
						"Quit this game and delete your save file?",
						["No", "Yes"],
						this._quitConfirmCallback,
						this
					)
				);
				break;
		}
	},
	/** Quit confirm callback.
	 */
	_quitConfirmCallback: function(option)
	{
		if(option == "Yes")
		{
			deleteSave();
			leaveGameMode();
			enterTitleMode();
		}
	},
	/** Look command callback.
	*/
	_lookCallback: function(x, y, canceled)
	{
		this._updateStatus();
		if(canceled)
			return;
		logWindow.pushMessage("You see " + this._map.getPositionDescription(x, y));
	},
	/** Rerender everything.
	*/
	render: function()
	{
		this._map.render();
	},
	/** Update the status display.
	*/
	_updateStatus: function()
	{
		// Current location message
		var psec = this._map.getPlayerSector();
		if(psec)
		{
			var status = psec.name;
			// status += " (" + (Math.floor(psec.heat * 1000) / 10) + "F)";
			//status += " [" + psec.index + "]";
			logWindow.tempMessage("%f0" + status);
		}
	}
};
